package com.zihan.domain.result;

import lombok.Data;

import java.io.Serializable;
import java.util.Map;

@Data
public class Result<T> implements Serializable {
    private Integer code;
    private String msg; //错误信息
    private T data; //数据
    private Map<String, Object> map;

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 200;
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 200;
        return result;
    }
    public static <T> Result<T> success(T object,Map<String,Object> map) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 200;
        result.map = map;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 400;
        return result;
    }

    public static <T> Result<T> error() {
        Result result = new Result();
        result.code = 400;
        return result;
    }
}